home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1893 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news1.cris.com!mariner!Crawford
  2. From: Crawford@mariner.cris.com (CRAWFORD)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What should be returned?
  5. Date: 17 Jan 1996 12:34:54 -0500
  6. Organization: Concentric Internet Services
  7. Message-ID: <Crawford.821899744@mariner>
  8. References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk>
  9. Reply-To: crawford@iac.net
  10. NNTP-Posting-Host: mariner.cris.com
  11.  
  12. phsung@cs.cuhk.hk (the CAReLess boy) writes:
  13. >Hi, all,
  14. >    It's said that the function main must return an integer value
  15. >but I just don't know what value should be returned.  Also, if I quit
  16. >main by exit(), what's the use of the return value?
  17. >    Any help?
  18.  
  19.     exit() also causes a value to be returned from main, the POSIX
  20. prottype for exit() is:
  21.  
  22. void exit(int status);
  23.  
  24.     As for what value should be returned, there should be two
  25. macros defined in stdlib.h, EXIT_SUCCESS and EXIT_FAILURE. Use
  26. those as the values to return from main and call exit() with.
  27.  
  28.     In the UNIX world (and, I believe, DOS), the standard is to
  29. return zero on success and non-zero on a failure. That's what the
  30. macros evaluate to, but I'd use the macros anyway, since they're easy
  31. to understand.
  32.  
  33. -- 
  34. Creature of the wheel, master of the internal combustion engine.
  35.  
  36. Robert Crawford                crawford@iac.net
  37. http://www.iac.net/~crawford
  38.